package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.SysMemberRai;
import com.ruoyi.system.mapper.SysMemberRaiMapper;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysRaiDetails;
import com.ruoyi.system.service.ISysRaiDetailsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 权益使用明细Controller
 * 
 * @author ruoyi
 * @date 2025-05-14
 */
@RestController
@RequestMapping("/system/raiDetails")
public class SysRaiDetailsController extends BaseController
{
    @Autowired
    private ISysRaiDetailsService sysRaiDetailsService;
    @Autowired
    private SysMemberRaiMapper sysMemberRaiMapper;

    /**
     * 查询权益使用明细列表
     */
    // @PreAuthorize("@ss.hasPermi('system:raiDetails:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysRaiDetails sysRaiDetails)
    {
        startPage();
        List<SysRaiDetails> list = sysRaiDetailsService.selectSysRaiDetailsList(sysRaiDetails);
        for (SysRaiDetails sysRaiDetail : list) {
            SysMemberRai sysMemberRai = sysMemberRaiMapper.selectSysMemberRaiById(sysRaiDetail.getRaiId());
            sysRaiDetail.setRaiName(ObjectUtils.isNotEmpty(sysMemberRai.getRaiName()) ? sysMemberRai.getRaiName() : "未知权益");
        }

        return getDataTable(list);
    }

    /**
     * 导出权益使用明细列表
     */
    // @PreAuthorize("@ss.hasPermi('system:raiDetails:export')")
    @Log(title = "权益使用明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysRaiDetails sysRaiDetails)
    {
        List<SysRaiDetails> list = sysRaiDetailsService.selectSysRaiDetailsList(sysRaiDetails);
        ExcelUtil<SysRaiDetails> util = new ExcelUtil<SysRaiDetails>(SysRaiDetails.class);
        util.exportExcel(response, list, "权益使用明细数据");
    }

    /**
     * 获取权益使用明细详细信息
     */
    // @PreAuthorize("@ss.hasPermi('system:raiDetails:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(sysRaiDetailsService.selectSysRaiDetailsById(id));
    }

    /**
     * 新增权益使用明细
     */
    // @PreAuthorize("@ss.hasPermi('system:raiDetails:add')")
    @Log(title = "权益使用明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysRaiDetails sysRaiDetails)
    {
        return toAjax(sysRaiDetailsService.insertSysRaiDetails(sysRaiDetails));
    }

    /**
     * 修改权益使用明细
     */
    // @PreAuthorize("@ss.hasPermi('system:raiDetails:edit')")
    @Log(title = "权益使用明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysRaiDetails sysRaiDetails)
    {
        return toAjax(sysRaiDetailsService.updateSysRaiDetails(sysRaiDetails));
    }

    /**
     * 删除权益使用明细
     */
    // @PreAuthorize("@ss.hasPermi('system:raiDetails:remove')")
    @Log(title = "权益使用明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(sysRaiDetailsService.deleteSysRaiDetailsByIds(ids));
    }
}
